package cn.edu.tju.ldj.analytics.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Good  implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5744385632058230660L;
	private String id;
	private String goodName;
	private String goodSrcUrl;
	private String goodTargetUrl;
	private String goodClass;
	private Map<String,Contract> goodContracts = new HashMap<String, Contract>();
	
	public Good(){
		if(loadData()){
			
		}
	}
	
	private boolean loadData(){
		
		return false;
	}
	
	public String getId(){
		return id;
	}

	public String getGoodName() {
		return goodName;
	}

	public void setGoodName(String goodName) {
		this.goodName = goodName;
	}

	public String getGoodSrcUrl() {
		return goodSrcUrl;
	}

	public void setGoodSrcUrl(String goodSrcUrl) {
		this.goodSrcUrl = goodSrcUrl;
	}

	public String getGoodClass() {
		return goodClass;
	}

	public void setGoodClass(String goodClass) {
		this.goodClass = goodClass;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getGoodTargetUrl() {
		return goodTargetUrl;
	}
	public void setGoodTargetUrl(String goodTargetUrl) {
		this.goodTargetUrl = goodTargetUrl;
	}

	public Map<String,Contract> getGoodContracts() {
		return goodContracts;
	}

	public void setGoodContracts(Map<String,Contract> goodContracts) {
		this.goodContracts = goodContracts;
	}
	
	public List<Contract> getGoodContractLst(){
		List<Contract> ctrctLst = new ArrayList<Contract>();
		
		List<String> keyset = new ArrayList<String>();
		for (String key : goodContracts.keySet()) {
			keyset.add(key);
		}
		int startIndex = 0;
		if(keyset.size() > 0){
			for (int i = 0; i < keyset.get(0).length(); i++) {
				if(Character.isDigit(keyset.get(0).charAt(i))){
					startIndex = i;
					break;
				}
			}
		}
		String temstr = new String();
		for (int i = 0; i < keyset.size(); i++) {
			for (int j = 1; j < keyset.size() - i; j++) {
				if(Integer.parseInt(keyset.get(j).substring(startIndex, keyset.get(j).length())) > Integer.parseInt(keyset.get(j-1).substring(startIndex, keyset.get(j-1).length()))){
					temstr = keyset.get(j);
					keyset.set(j,keyset.get(j-1));
					keyset.set(j-1,temstr);
				}
			}
		}
		for (int i = 0; i < keyset.size(); i++) {
			ctrctLst.add(goodContracts.get(keyset.get(i)));
		}
		
		return ctrctLst;
	}
	
}
